package com.office.forum.manage.article.service.impl;

import java.util.List;

import com.office.common.utils.DateUtils;
import com.office.forum.manage.category.domain.ForumPostCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.office.forum.manage.article.mapper.ForumPostsMapper;
import com.office.forum.manage.article.domain.ForumPosts;
import com.office.forum.manage.article.service.IForumPostsService;

import static com.office.common.utils.SecurityUtils.getUserId;
import static com.office.common.utils.SecurityUtils.getUsername;

/**
 * 帖子Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-16
 */
@Service
public class ForumPostsServiceImpl implements IForumPostsService 
{
    @Autowired
    private ForumPostsMapper forumPostsMapper;

    /**
     * 查询帖子
     * 
     * @param postId 帖子主键
     * @return 帖子
     */
    @Override
    public ForumPosts selectForumPostsByPostId(Long postId)
    {
        return forumPostsMapper.selectForumPostsByPostId(postId);
    }

    /**
     * 查询帖子列表
     * 
     * @param forumPosts 帖子
     * @return 帖子
     */
    @Override
    public List<ForumPosts> selectForumPostsList(ForumPosts forumPosts)
    {
        return forumPostsMapper.selectForumPostsList(forumPosts);
    }

    /**
     * 新增帖子
     * 
     * @param forumPosts 帖子
     * @return 结果
     */
    @Override
    public int insertForumPosts(ForumPosts forumPosts)
    {
        forumPosts.setUserId(getUserId());
        forumPosts.setCreatedAt(DateUtils.getNowDate());
        forumPosts.setName(getUsername());
        return forumPostsMapper.insertForumPosts(forumPosts);
    }

    /**
     * 修改帖子
     * 
     * @param forumPosts 帖子
     * @return 结果
     */
    @Override
    public int updateForumPosts(ForumPosts forumPosts)
    {
        forumPosts.setUpdatedAt(DateUtils.getNowDate());
        return forumPostsMapper.updateForumPosts(forumPosts);
    }

    /**
     * 批量删除帖子
     * 
     * @param postIds 需要删除的帖子主键
     * @return 结果
     */
    @Override
    public int deleteForumPostsByPostIds(Long[] postIds)
    {
        return forumPostsMapper.deleteForumPostsByPostIds(postIds);
    }

    /**
     * 删除帖子信息
     * 
     * @param postId 帖子主键
     * @return 结果
     */
    @Override
    public int deleteForumPostsByPostId(Long postId)
    {
        return forumPostsMapper.deleteForumPostsByPostId(postId);
    }

    @Override
    public List<ForumPostCategory> getCategoryName() {
        return forumPostsMapper.getCategoryName();
    }

    /**
     * 用户ID查帖子
     * @param userId
     * @return
     */
    @Override
    public List<ForumPosts> selectForumPostsByUserId(Long userId) {
        return forumPostsMapper.selectForumPostsByUserId(userId);
    }
    /**
     * id批量查询收藏的帖子
     */
    @Override
    public List<ForumPosts> getPostsByIds(List<Long> postIds) {
        return forumPostsMapper.getPostsByIds(postIds);
    }
}
